#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


const char* path="/home/csy/linux-practice/code_4_7/mycmd";

int main(int argc,char* argv[],char* env[])
{
    pid_t id = fork();
    if(id==0)
    {
        //子进程
        printf("I am child process, pid:%d ppid:%d\n",getpid(),getppid());
        sleep(2);
        execle(path,"mycmd","-b",NULL,env);
       // execl(path,"mycmd","-a",NULL);
        //execlp("ls","ls","-l","-a",NULL);
        //char* const _argv[4]={(char*)"ls",(char*)"-a",(char*)"-l",NULL};
        //execv("/usr/bin/ls",_argv);
        //execl("/usr/bin/ls","ls","-l",NULL);
        
        exit(1);
    }

    else{
        //父进程
        printf("I am father process, pid:%d\n",getpid());
        int status=0;
        pid_t ret = waitpid(-1,&status,0);
        if(ret>0)
        {
            printf("wait sucess, exit code:%d\n",WEXITSTATUS(status));
        }
    }

    return 0;
}
